#include "Mesh.h"
#include <glm/glm.hpp>

Mesh::Mesh(){
	vertices = new glm::vec3 [5];
	indices = new GLubyte [18];
	normals = new float [54];

	glm::vec3 norm = glm::normalize(glm::vec3(3, 0.5, 6));

	vertices[0] = glm::vec3(0.f, 5.f, 0.f);
	vertices[1] = glm::vec3(-1.f, -1.f, 0.f);
	vertices[2] = glm::vec3(0.f, -1.f, 0.5f);
	vertices[3] = glm::vec3(1.f, -1.f, 0.f);
	vertices[4] = glm::vec3(0.f, -1.f, -0.5f);

	indices[0] = 0; indices[1] = 1;	indices[2] = 2;
	indices[3] = 0;	indices[4] = 2;	indices[5] = 3;
	indices[6] = 0;	indices[7] = 3;	indices[8] = 4;
	indices[9] = 0;	indices[10] = 4; indices[11] = 1;
	indices[12] = 1; indices[13] = 4; indices[14] = 3;
	indices[15] = 1; indices[16] = 3; indices[17] = 2;


	normals[0] = -norm.x; normals[1] = norm.y; normals[2] = norm.z; 
	normals[3] = -norm.x; normals[4] = norm.y; normals[5] = norm.z;
	normals[6] = -norm.x; normals[7] = norm.y; normals[8] = norm.z;

	normals[9] = -norm.x; normals[10] = -norm.y; normals[11] = -norm.z; 
	normals[12] = -norm.x; normals[13] = -norm.y; normals[14] = -norm.z;
	normals[15] = -norm.x; normals[16] = -norm.y; normals[17] = -norm.z;

	normals[18] = norm.x; normals[19] = norm.y; normals[20] = -norm.z; 
	normals[21] = norm.x; normals[22] = norm.y; normals[23] = -norm.z;
	normals[24] = norm.x; normals[25] = norm.y; normals[26] = -norm.z;

	normals[27] = -norm.x; normals[28] = norm.y; normals[29] = -norm.z; 
	normals[30] = -norm.x; normals[31] = norm.y; normals[32] = -norm.z;
	normals[33] = -norm.x; normals[34] = norm.y; normals[35] = -norm.z;

	normals[36] = 0; normals[37] = -1; normals[38] = 0; 
	normals[39] = 0; normals[40] = -1; normals[41] = 0;
	normals[42] = 0; normals[43] = -1; normals[44] = 0;

	normals[45] = 0; normals[46] = -1; normals[47] = 0; 
	normals[48] = 0; normals[49] = -1; normals[50] = 0;
	normals[51] = 0; normals[52] = -1; normals[53] = 0;
}

void Mesh::draw(){
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);

	glColor3f(0, 0.7, 0.1);

	glNormalPointer(GL_FLOAT, 0, normals);
	glVertexPointer(3, GL_FLOAT, 0, vertices);
	
	glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_BYTE, indices);

	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);

}